import { Injectable } from '@angular/core';
import { MdcSnackbar, MdcSnackbarConfig } from '@angular-mdc/web';

@Injectable()
export class SnackbarService {

  constructor(
    private snackbar: MdcSnackbar
  ) { }

  create(message: string, type?: SnackbarType) {

    const snackbarConfig: MdcSnackbarConfig = {
      dismiss: true,
      timeoutMs: 4000,
    };

    if (type === SnackbarType.Error) {
      Object.assign(snackbarConfig, { classes: 'snackbar-error' });
    }

    if (type === SnackbarType.Success) {
      Object.assign(snackbarConfig, { classes: 'snackbar-success' });
    }

    this.snackbar.open(message, null, snackbarConfig);
  }

}

export enum SnackbarType {
  Error,
  Success
}
